﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Template.CodeGenerator
{
   public static class TypeHelper
    {

        public static string ToSingleTypeName(string typeName,bool isNullable = false)
        {
            
            string name = typeName;
            switch (typeName)
            {
                case "Int64":
                    name = "long";
                    break;
                //case "Byte?[]":
                //    name = "byte?[]";
                //    break;
                case  "Byte[]":
                    name = "byte[]";
                    break;
                case "Boolean":
                    name = "bool";
                    break;
                case "String":
                    name = "string";
                    break;
                case "Decimal":
                    name = "decimal";
                    break;
                case "Double":
                    name = "double";
                    break;
                case "Int32":
                    name = "int";
                    break;
                case "Int16":
                    name = "short";
                    break;
                case "Object":
                    name = "object";
                    break;
                case "Byte":
                    name = "byte";
                    break;
            }
            if(isNullable&& name != "object" && name != "string")
            {
                var arrName = name.Split("[]".ToCharArray());
                if (arrName.Count() < 1)
                {
                    name = $"{arrName[0]}?{arrName[1]}";
                }

                {
                    name = $"{name}?";
                }
              
             
            }
            return name;
        }
    }
}
